package com.dede.monochromatism.db

import com.dede.monochromatism.data.AppInfo

/**
 * @author hsh
 * @date 2017/9/21 10:47.
 * @doc
 */
fun List<AppInfo>.contains(packageName: String): Boolean {
    this.forEach {
        if (it.packageName == packageName) {
            return true
        }
    }
    return false
}

object PackageDb {

    private val sOpenList = emptyList<AppInfo>().toMutableList()
    private val sIgnoreList = emptyList<AppInfo>().toMutableList()

    @Synchronized
    fun getOpenList() = sOpenList

    @Synchronized
    fun getIgnoreList() = sIgnoreList

    @Synchronized
    fun setOpenList(list: List<AppInfo>) {
        sOpenList.clear()
        sOpenList.addAll(list)
    }

    @Synchronized
    fun setIgnoreList(list: List<AppInfo>) {
        sIgnoreList.clear()
        sIgnoreList.addAll(list)
    }

    @Synchronized
    fun addOpenList(vararg date: AppInfo) {
        date.forEach { sOpenList.add(it) }
    }

    @Synchronized
    fun removeOpenList(vararg date: AppInfo) {
        date.forEach { sOpenList.remove(it) }
    }

    @Synchronized
    fun addIgnoreList(vararg date: AppInfo) {
        date.forEach { sIgnoreList.add(it) }
    }

    @Synchronized
    fun removeIgnoreList(vararg date: AppInfo) {
        date.forEach { sIgnoreList.remove(it) }
    }
}